package com.panfeng.xcloud.boss.provider.assets.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.panfeng.xcloud.boss.provider.assets.dto.request.BuyActiveCodeReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.BuyPointCardReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.TransferReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.WithdrawReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.BuyActiveCodeRespDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.BuyPointCardRespDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.TransferRespDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.WithdrawRespDTO;
import com.panfeng.xcloud.boss.provider.assets.service.IUserWalletService;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.BuyActiveCodeReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.BuyPointCardReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.TransferReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.WithdrawReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.BuyActiveCodeRespVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.BuyPointCardRespVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.TransferRespVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.WithdrawRespVO;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.common.core.web.vo.ResponseVO;
import com.panfeng.xcloud.common.security.annotation.NotNeedAccess;
import com.panfeng.xcloud.common.security.web.support.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 钱包操作模块
 *
 * @author xiaobo
 * @version 1.0
 * @since 2021-03-23
 */
//@ApiIgnore
@RestController
@RequestMapping("assets/userWallet")
@Api(tags = {"钱包操作模块"})
@Slf4j
public class UserWalletController extends BaseController {

    @Autowired
    private IUserWalletService iUserWalletService;

    /**
     * 用户发起提币
     *
     * @return
     */
    @NotNeedAccess
    @PostMapping(value = "/withdraw", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "用户发起提币(肖博)", httpMethod = "POST", notes = "用户发起提币(肖博)")
    public ResponseVO<WithdrawRespVO> withdraw(@RequestBody @Valid WithdrawReqVO reqVo, BindingResult bindingResult) {
        logger.info(">>>> 当前withdraw请求参数：{} <<<", (null != reqVo ? JSONObject.toJSONString(reqVo) : ""));
        WithdrawReqDTO withdrawReqDTO = ConvertUtils.convert(reqVo, WithdrawReqDTO.class);
        WithdrawRespDTO withdrawRespDTO = iUserWalletService.withdraw(withdrawReqDTO);
        WithdrawRespVO withdrawRespVO = ConvertUtils.convert(withdrawRespDTO, WithdrawRespVO.class);
        logger.info(">>>> 当前withdraw响应内容：{} <<<", (null != withdrawRespVO ? JSONObject.toJSONString(withdrawRespVO) : ""));
        return ResponseVO.with(withdrawRespVO);
    }

    /**
     * 用户互转
     *
     * @return
     */
    @NotNeedAccess
    @PostMapping(value = "/transfer", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "用户互转(肖博)", httpMethod = "POST", notes = "用户互转(肖博)")
    public ResponseVO<TransferRespVO> transfer(@RequestBody @Valid TransferReqVO reqVo, BindingResult bindingResult) {
        logger.info(">>>> 当前transfer请求参数：{} <<<", (null != reqVo ? JSONObject.toJSONString(reqVo) : ""));
        TransferReqDTO transferReqDTO = ConvertUtils.convert(reqVo, TransferReqDTO.class);
        TransferRespDTO transferRespDTO = iUserWalletService.transfer(transferReqDTO);
        TransferRespVO transferRespVO = ConvertUtils.convert(transferRespDTO, TransferRespVO.class);
        logger.info(">>>> 当前transfer响应内容：{} <<<", (null != transferRespVO ? JSONObject.toJSONString(transferRespVO) : ""));
        return ResponseVO.with(transferRespVO);
    }

    /**
     * 购买点卡
     *
     * @return
     */
    @NotNeedAccess
    @PostMapping(value = "/buyPointCard", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "购买点卡(肖博)", httpMethod = "POST", notes = "购买点卡(肖博)")
    public ResponseVO<BuyPointCardRespVO> buyPointCard(@RequestBody @Valid BuyPointCardReqVO reqVo, BindingResult bindingResult) {
        logger.info(">>>> 当前buyPointCard请求参数：{} <<<", (null != reqVo ? JSONObject.toJSONString(reqVo) : ""));
        BuyPointCardReqDTO buyPointCardReqDTO = ConvertUtils.convert(reqVo, BuyPointCardReqDTO.class);
        BuyPointCardRespDTO buyPointCardRespDTO = iUserWalletService.buyPointCard(buyPointCardReqDTO);
        BuyPointCardRespVO buyPointCardRespVO = ConvertUtils.convert(buyPointCardRespDTO, BuyPointCardRespVO.class);
        logger.info(">>>> 当前buyPointCard响应内容：{} <<<", (null != buyPointCardRespVO ? JSONObject.toJSONString(buyPointCardRespVO) : ""));
        return ResponseVO.with(buyPointCardRespVO);
    }

    /**
     * 购买激活码
     *
     * @return
     */
    @NotNeedAccess
    @PostMapping(value = "/buyActiveCode", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "购买激活码(肖博)", httpMethod = "POST", notes = "购买激活码(肖博)")
    public ResponseVO<BuyActiveCodeRespVO> buyActiveCode(@RequestBody @Valid BuyActiveCodeReqVO reqVo, BindingResult bindingResult) {
        logger.info(">>>> 当前buyActiveCode请求参数：{} <<<", (null != reqVo ? JSONObject.toJSONString(reqVo) : ""));
        BuyActiveCodeReqDTO buyActiveCodeReqDTO = ConvertUtils.convert(reqVo, BuyActiveCodeReqDTO.class);
        BuyActiveCodeRespDTO buyActiveCodeRespDTO = iUserWalletService.buyActiveCode(buyActiveCodeReqDTO);
        BuyActiveCodeRespVO buyActiveCodeRespVO = ConvertUtils.convert(buyActiveCodeRespDTO, BuyActiveCodeRespVO.class);
        logger.info(">>>> 当前buyActiveCode响应内容：{} <<<", (null != buyActiveCodeRespVO ? JSONObject.toJSONString(buyActiveCodeRespVO) : ""));
        return ResponseVO.with(buyActiveCodeRespVO);
    }

}
